<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>

<head>
    <title>Home</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <!-- Bootstrap Core CSS -->
    <link href="${pageContext.request.contextPath}/css/bootstrap.min.css" rel='stylesheet' type='text/css'/>
    <!-- Custom CSS -->
    <link href="${pageContext.request.contextPath}/css/backdoor.css" rel='stylesheet' type='text/css'/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/morris.css" type="text/css"/>
    <!-- Graph CSS -->
    <link href="${pageContext.request.contextPath}/css/font-awesome.css" rel="stylesheet">
    <!-- jQuery -->
    <script src="${pageContext.request.contextPath}/js/jquery-2.1.4.min.js"></script>
    <%--mask--%>
    <link href="${pageContext.request.contextPath}/css/mask.css" rel="stylesheet">
    <%--分页--%>
    <script src="${pageContext.request.contextPath}/js/myPagination.js"></script>
    <%--弹窗--%>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/BeAlert.css" type="text/css"/>
    <script src="${pageContext.request.contextPath}/js/BeAlert.js"></script>
    <script>
        $(function () {
            var colors = ["sl-primary", "sl-success", "sl-info", "sl-warning", "sl-danger", "sl-alert", "sl-system"];
            var lightness = ["light", "", "dark"];
            var illegalType = ["提问", "评论", "回答", "评论"];
            var status = ["待处理", "已忽略"];
            $(".sl-item").each(function () {
                // 为事件之前的小圆点着色
                var i = Math.floor(Math.random() * (colors.length));
                var j = Math.floor(Math.random() * (colors.length));
                $(this).addClass(colors[i]).addClass(lightness[j]);
                //为事件计算时间
                var timeItem = $(this).children(".sl-content").children(".item_time");
                var differTime = computeDifferTime(timeItem.text());
                timeItem.text(differTime);
                //显示事件类型
                var itemType = timeItem.next().children(".item_type");
                var typeId = itemType.text();
                itemType.text(illegalType[typeId]);
                //显示处理状态
                var statusType = $(this).children(".pull-right").children(".text-muted");
                var statusId = statusType.text();
                if (parseInt(statusId) === 0) {
                    statusType.text(status[0]).css("font-weight", "bold").css("color", "black");
                } else {
                    statusType.text(status[1]).css("pointer-events", "none").css("color", "grey");
                }

            });

            // 分页
            var div = $("#pagination");
            var curPage = ${pageInfo.pageNum};
            var allPage = ${pageInfo.pages};
            var length = 5;
            paginationConstructor(div, length, curPage, allPage);
        });


        //计算已过时间
        function computeDifferTime(startTime) {
            var differTime = new Date().getTime() - parseInt(startTime);
            var day = Math.floor(differTime / (24 * 60 * 60 * 1000));
            if (day > 0) return day + '天前';
            var hours = Math.floor(differTime / (60 * 60 * 1000));
            if (hours > 0) return hours + '小时前';
            var minutes = Math.floor(differTime / (60 * 1000));
            if (minutes > 0) return minutes + '分钟前';
            var seconds = Math.floor(differTime / 1000);
            return seconds + '秒前';
        }

        //处理违纪
        function deal(id, type, reason, objectContent) {
            var illegalType = ["提问", "评论", "回答", "评论"];
            confirm("违规" + illegalType[type] + ": " + reason,
                "内容:" + objectContent,
                function (isConfirm) {
                    if (isConfirm) {
                        window.location.href = '${pageContext.request.contextPath}/backdoor/illegalities/delete/' + id;
                    } else {
                        window.location.href = '${pageContext.request.contextPath}/backdoor/illegalities/ignore/' + id;
                    }
                }, {
                    type: 'warning',
                    confirmButtonText: '删除该' + illegalType[type],
                    cancelButtonText: '忽略',
                    width: 400
                }
            );
        }

    </script>

</head>

<body>
<div class="page-container">
    <!--/content-inner-->
    <div class="left-content">
        <div class="mother-grid-inner">
            <!--header start here-->
            <jsp:include page="backdoor_header.jsp"/>
            <!--heder end here-->
            <!--导航-->
            <ol class="breadcrumb">
                <li class="breadcrumb-item">
                    <a href="${pageContext.request.contextPath}/backdoor/index">主页</a>
                    <i class="fa fa-angle-right"></i>
                    <a href="${pageContext.request.contextPath}/backdoor/illegalities">违规处理</a>
                    <i class="fa fa-angle-right"></i>
                </li>
            </ol>
            <%--一列记录--%>
            <div class="col-sm-6 w3-agile-crd">
                <div class="card">
                    <div class="card-body card-padding">
                        <div class="widget">
                            <div class="widget-body">
                                <div class="streamline">
                                    <c:forEach items="${pageInfo.list}" var="item" begin="0" end="7">
                                        <div class="sl-item">
                                            <div class="sl-content pull-left">
                                                <small class="item_time text-muted">${item.time}</small>
                                                <div>
                                                    <a href="javascript:void(0);"
                                                       onclick="openMask(${item.toId});">${item.toUser.name}</a>
                                                    的
                                                    <a href="javascript:void(0);"
                                                       onclick="deal(${item.id},${item.type},'${item.reason}','${item.objectContent}');"
                                                       class="item_type">${item.type}</a>
                                                    因
                                                    <span style="color: red">${item.reason}</span>
                                                    被
                                                    <a href="javascript:void(0);"
                                                       onclick="openMask(${item.fromId});">${item.fromUser.name}</a>
                                                    举报
                                                </div>
                                            </div>
                                            <div class="pull-right">
                                                <a href="javascript:void(0);"
                                                   onclick="deal(${item.id},${item.type},'${item.reason}','${item.objectContent}');"
                                                   class="text-muted">${item.status}</a>
                                            </div>
                                            <div class="clearfix"></div>
                                        </div>
                                    </c:forEach>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
            <%--一列记录--%>
            <div class="col-sm-6 w3-agile-crd">
                <div class="card">
                    <div class="card-body card-padding">
                        <div class="widget">
                            <div class="widget-body">
                                <div class="streamline">
                                    <c:forEach items="${pageInfo.list}" var="item" begin="8" end="15">
                                        <div class="sl-item">
                                            <div class="sl-content pull-left">
                                                <small class="item_time text-muted">${item.time}</small>
                                                <div>
                                                    <a href="javascript:void(0);"
                                                       onclick="openMask(${item.toId});">${item.toUser.name}</a>
                                                    的
                                                    <a href="javascript:void(0);"
                                                       onclick="deal(${item.id},${item.type},'${item.reason}','${item.objectContent}');"
                                                       class="item_type">${item.type}</a>
                                                    因
                                                    <span style="color: red">${item.reason}</span>
                                                    被
                                                    <a href="javascript:void(0);"
                                                       onclick="openMask(${item.fromId});">${item.fromUser.name}</a>
                                                    举报
                                                </div>
                                            </div>
                                            <div class="pull-right">
                                                <a href="javascript:void(0);"
                                                   onclick="deal(${item.id},${item.type},'${item.reason}','${item.objectContent}');"
                                                   class="text-muted">${item.status}</a>
                                            </div>
                                            <div class="clearfix"></div>
                                        </div>
                                    </c:forEach>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>

            <!--分页-->
            <div class="clearfix"></div>
            <div id="pagination"></div>
            <div class="clearfix"></div>

            <!--copy rights start here-->
            <jsp:include page="backdoor_footer.jsp"/>
            <!--COPY rights end here-->
        </div>
    </div>
    <!--//content-inner-->
    <!--/sidebar-menu-->
    <jsp:include page="backdoor_sidebar.jsp"/>
    <div class="clearfix"></div>
</div>

<%--//用户页弹窗--%>
<jsp:include page="userPage.jsp"/>
<!-- Bootstrap Core JavaScript -->
<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
<!-- /Bootstrap Core JavaScript -->

</body>

</html>